<template>
  <div>
    <div class="news_title">
      <div class="news">
        <h1>新鲜好物</h1>
        <span>新鲜好物 品质靠谱</span>
      </div>
      <p>
        <a href="#">查看更多</a>
      </p>
    </div>
    <div class="goods_list">
      <div
        class="list_one"
        @click="turnInfo(item.id)"
        v-for="(item, index) in newsList"
        :key="index"
      >
        <img :src="item.picture" alt="" />
        <h2>{{ item.name }}</h2>
        <p class="price">￥{{ item.price }}</p>
      </div>
    </div>
  </div>
</template>
<script>
import { _getNewGoods } from '../../../api/home'
export default {
  data () {
    return {
      newsList: [] //新鲜好物列表
    }
  },
  created () {
    this.getNew()
  },
  methods: {
    turnInfo (id) {
      // 跳转详情页 并传参
      this.$router.push({
        name: 'detail',
        query: {
          id: id
        }
      })
    },
    async getNew () {
      var res = await _getNewGoods()
      console.log(res)
      this.newsList = res.data.result
    }
  }
}
</script>
<style lang="less">
.news_title {
  width: 1240px;
  height: 60px;
  margin: 0 auto;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  .news {
    display: flex;
  }
}
.goods_list {
  width: 1240px;
  margin: 0 auto;
  height: 406px;
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  .list_one {
    width: 306px;
    height: 406px;
    img {
      width: 306px;
      height: 306px;
    }
    h2 {
      line-height: 60px;
      font-size: 16px;
    }
    .price {
      color: red;
      font-size: 18px;
    }
  }
}
</style>
